package com.${projectName}.${moduleName}.rest.${packageName}.restful.api;

import com.hkbt.base.frame.web.HKRestController;
import com.${projectName}.${moduleName}.rest.${packageName}.transfer.${tableName}BOToVO;
import com.${projectName}.${moduleName}.service.${packageName}.service.${tableName}Service;
import io.swagger.annotations.Api;
import javax.annotation.Resource;
import com.hkbt.base.frame.domain.bo.PageBO;
import com.hkbt.base.frame.domain.vo.PageVO;
import com.hkbt.base.frame.domain.param.DefaultPageParam;
import com.hkbt.base.frame.web.response.result.AjaxResult;
import com.${projectName}.${moduleName}.param.${packageName}.${tableName}Param;
import com.${projectName}.${moduleName}.service.${packageName}.bo.${tableName}BO;
import com.${projectName}.${moduleName}.rest.${packageName}.restful.vo.${tableName}RVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;

/**
 * @author ${author}
 */
@Api(tags = "web-${comment}")
@HKRestController("/api/${lowerTableName}/v1")
public class ${tableName}Restful {

    @Resource
    private ${tableName}Service ${lowerTableName}Service;
    @Resource
    private ${tableName}BOToVO ${lowerTableName}BOToVO;

    @ApiOperation(value ="查询分页列表-1.0", notes = "${notes}")
    @PostMapping("/get${tableName}Page")
    public AjaxResult<PageVO<${tableName}RVO>> get${tableName}Page(@ApiParam(value = "查询参数", required = true) @RequestBody @Validated DefaultPageParam<${tableName}Param> param) {
        AjaxResult ajaxResult = AjaxResult.buildSuccess();
        PageBO<${tableName}BO> pageBO = ${lowerTableName}Service.get${tableName}Page(param);
        ajaxResult.setData(${lowerTableName}BOToVO.toPage(pageBO));
        return ajaxResult;
    }

    @ApiOperation(value ="查询列表-1.0", notes = "${notes}")
    @PostMapping("/get${tableName}List")
    public AjaxResult<List<${tableName}RVO>> get${tableName}List(@ApiParam(value = "查询参数", required = true) @RequestBody @Validated ${tableName}Param param) {
        AjaxResult ajaxResult = AjaxResult.buildSuccess();
        List<${tableName}BO> listBO = ${lowerTableName}Service.get${tableName}List(param);
        ajaxResult.setData(${lowerTableName}BOToVO.toVos(listBO));
        return ajaxResult;
    }

    @ApiOperation(value ="获取详情-1.0", notes = "${notes}")
    @GetMapping("/get${tableName}ById")
    public AjaxResult<${tableName}RVO> get${tableName}ById(@ApiParam(value = "查询id", required = true) @RequestParam Long id) {
        AjaxResult ajaxResult = AjaxResult.buildSuccess();
        ${tableName}BO BO = ${lowerTableName}Service.get${tableName}ById(id);
        ajaxResult.setData(${lowerTableName}BOToVO.toVO(BO));
        return ajaxResult;
    }

    @ApiOperation(value ="新增-1.0", notes = "${notes}")
    @PostMapping("/insert${tableName}")
    public AjaxResult<Long> insert${tableName}(@ApiParam(value = "新增参数", required = true) @RequestBody @Validated ${tableName}Param param) {
        AjaxResult ajaxResult = AjaxResult.buildSuccess();
        ajaxResult.setData(${lowerTableName}Service.insert${tableName}(param));
        return ajaxResult;
    }

    @ApiOperation(value ="更新-1.0", notes = "${notes}")
    @PostMapping("/update${tableName}")
    public AjaxResult<Boolean> update${tableName}(@ApiParam(value = "修改参数", required = true) @RequestBody @Validated ${tableName}Param param) {
        AjaxResult ajaxResult = AjaxResult.buildSuccess();
        ajaxResult.setData(${lowerTableName}Service.update${tableName}(param));
        return ajaxResult;
    }

    @ApiOperation(value ="删除-1.0", notes = "${notes}")
    @GetMapping("/delete${tableName}")
    public AjaxResult<Boolean> delete${tableName}(@ApiParam(value = "删除参数", required = true) @RequestParam Long id) {
        AjaxResult ajaxResult = AjaxResult.buildSuccess();
        ajaxResult.setData(${lowerTableName}Service.delete${tableName}(id));
        return ajaxResult;
    }
                                

}
